package com.scen.upload.vo;

import java.util.ArrayList;
import java.util.List;

/**
 * 省份市区数据层次构造器
 */
public class OtherNodeBuilder {

    public static List<OtherNode> build(List<OtherNode> otherNodes, Integer typeId) {
        ArrayList<OtherNode> nodes = new ArrayList<>();
        for (OtherNode n1 : otherNodes) {
            if (n1.getType() == typeId) {
                nodes.add(n1);
            }
            for (OtherNode n2 : otherNodes) {
                if (n1.getValue() == n2.getType()) {
                    n1.getChildren().add(n2);
                    if(n2.getChildren().size()==0){
                        n2.setChildren(null);
                    }
                }
            }
        }
        return nodes;
    }
}
